package com.xm.xmds1705083.web.controller;

import com.xm.xmds1705083.service.dto.DuoduoParkDto;
import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xmds1705083.service.service.DuoduoParkService;
import com.xm.xmds1705083.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 杭州新苗网络科技有限公司
 *
 * @author meihf
 * @create 2017/6/14
 * @description
 */
@Controller
@RequestMapping("/park")
public class ParkController extends BaseController{

    @Autowired
    DuoduoParkService duoduoParkService;

    /**
     * 最近的四个停车场
     * @param searchDto
     * @return
     */
    @RequestMapping("/closeParks")
    @ResponseBody
    public ResultDto closeParks(@RequestBody SearchDto searchDto){
        return duoduoParkService.closeParks(searchDto);
    }

    /**
     * 根据车库名进行模糊搜索
     */
    @RequestMapping("/findCloseByName")
    @ResponseBody
    public ResultDto findCloseByName(@RequestBody SearchDto searchDto){
        return duoduoParkService.findCloseByName(searchDto);
    }

    /**
     * 根据车库名进行模糊搜索
     */
    @RequestMapping("/findCloseByNames")
    @ResponseBody
    public ResultDto findCloseByNames(@RequestBody SearchDto searchDto){
        return duoduoParkService.findCloseByNames(searchDto);
    }

    /**
     * 根据车库地址进行模糊搜索
     */
    @RequestMapping("/findCloseByAddress")
    @ResponseBody
    public ResultDto findCloseByAddress(@RequestBody SearchDto searchDto){
        return duoduoParkService.findCloseByAddress(searchDto);
    }

    /**
     * 附近优惠停车场
     */
    @RequestMapping("/findPrivilege")
    @ResponseBody
    public ResultDto findPrivilege(@RequestBody SearchDto searchDto){
        return duoduoParkService.findPrivilege(searchDto);
    }

    /**
     * 根据停车场id进行搜索详情
     */
    @RequestMapping("/findById")
    @ResponseBody
    public ResultDto findById(@RequestBody SearchDto searchDto){
        return duoduoParkService.findById(searchDto);
    }

    /**
     * 反向寻车
     */
    @RequestMapping("/findMyCarPosition")
    @ResponseBody
    public ResultDto findMyCarPosition(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoParkService.findMyCarPosition(searchDto);
    }

    /****
     * 停车缴费
     */
    @RequestMapping("/getTotalMoney")
    @ResponseBody
    public ResultDto getTotalMoney(@RequestBody SearchDto searchDto){
       /* searchDto.setAppUserId(getUserId());*/
        String authorization =   getRequest().getHeader("AUTHORIZATION");
        if (authorization!=null){
            searchDto.setAppUserId(Math.abs( Long.valueOf( authorization.split("\\_")[0] ) ));
        }
        return duoduoParkService.getTotalMoney(searchDto);
    }

    /**
     * 缴费通知
     */
    @RequestMapping("/savePayRecord")
    @ResponseBody
    public ResultDto savePayRecord(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoParkService.savePayRecord(searchDto);
    }

    /**
     * 查询停车场信息
     */
    @RequestMapping("/searchParkInfoById")
    @ResponseBody
    public ResultDto getParkInfo(@RequestBody SearchDto searchDto){
        searchDto.setAppUserId(getUserId());
        return duoduoParkService.searchParkInfoById(searchDto);
    }



}
